﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Maticsoft.DBUtility;


namespace SkWeb.FAXZ
{
    public partial class FAXZ : System.Web.UI.Page
    {
        DataTable dtDropList = null;
        DataTable DtDropList
        {
            get
            {
                if (dtDropList == null)
                {
                    dtDropList = OracleHelper.Query("select name from tb_sjfa").Tables[0];
                }
                return dtDropList;
            }
            set
            {
                dtDropList = value;
            }
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                btnFirst.Text = "最首页";
                btnPrev.Text = "前一页";
                btnNext.Text = "下一页";
                btnLast.Text = "最后页";
                ViewState["Filter"] = "";
                GridViewTable_Load();
            }
            //GridViewTable_Load();
        }

        // 读取 表信息
        protected void GridViewTable_Load()
        {
            DataTable dt = new DataTable();
            dt = OracleHelper.Query("select jh,xh,qyrq from as03").Tables[0];

            GridViewTable.DataSource = dt.DefaultView;
            GridViewTable.DataBind();
            ViewState["rowCount"] = dt.Rows.Count;
            GridViewTable.DataKeyNames = new string[] { "jh" };
            lblCurrentIndex.Text = "第<font color='red'>" + (GridViewTable.PageIndex + 1).ToString() + " </font>页";
            lblPageCount.Text = "总共 <font color='red'>" + GridViewTable.PageCount.ToString() + " </font>页";
        }
        protected void ddlFaName_SelectedIndexChanged(object sender, EventArgs e)
        {
        }
        /// <summary>
        /// 查看详细情况
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lb_Click(object sender, EventArgs e)
        {
            LinkButton lb = sender as LinkButton;
            GridViewRow row = (GridViewRow)lb.NamingContainer;
            DropDownList ddlFaName = row.FindControl("faName") as DropDownList;
            string strFa = ddlFaName.Text;
            string strJh = row.Cells[0].Text;
            Response.Redirect("FACX.aspx?jh=" + strJh + "&fa=" + strFa);

            //throw new NotImplementedException();
        }
        // 数据表信息 换页事件
        protected void GridViewTable_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridViewTable.PageIndex = e.NewPageIndex;
            //ViewState["page"]=
            GridViewTable_Load();
        }
        protected void PagerButtonClick(object sender, EventArgs e)
        {
            string arg = ((LinkButton)sender).CommandArgument.ToString();
            switch (arg)
            {
                case "next":
                    GridViewTable.PageIndex = GridViewTable.PageIndex + 1;
                    break;
                case "prev":
                    if (GridViewTable.PageIndex > 0)
                    {
                        GridViewTable.PageIndex = GridViewTable.PageIndex - 1;
                    }
                    break;
                case "last":
                    GridViewTable.PageIndex = GridViewTable.PageCount - 1;
                    break;
                case "0":
                    GridViewTable.PageIndex = 0;
                    break;
            }
            GridViewTable_Load();
        }





        // 数据表信息 搜索
        protected void ButtonSeach_Click(object sender, EventArgs e)
        {
            if (TextBoxTABLE_CODE_S.Text.Length == 0)
            {
                ViewState["Filter"] = "";
            }
            else
                ViewState["Filter"] = "%" + TextBoxTABLE_CODE_S.Text.ToUpper() + "%";
            GridViewTable_Load();

        }

        protected void GridViewTable_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DropDownList ddlTableName = e.Row.FindControl("faName") as DropDownList;
                ddlTableName.DataSource = DtDropList;
                ddlTableName.DataTextField = "name";
                ddlTableName.DataBind();
                ddlTableName.Items.Insert(0, new ListItem(" "));

            }
        }

    }
}